package com.tamir.template.express.parse;

import com.tamir.template.bean.TNode;
import com.tamir.template.config.TemplateNodeTypeConfig;

/**
 * @author : tanggh
 * @description :〈描述〉
 * @date : 2016/11/8
 */
public class DefaultIfHandleParse extends AbstractLogicHandleParse
{

    /**
     * 设置node的输入输出关键字和对应的值
     *
     * @param node
     */
    public void parseIOKeyForNode(TNode node)
    {
        if(node != null && node.gettLogicType().gettLogicType().equalsIgnoreCase
                (TemplateNodeTypeConfig.NODE_TYPE_IF)){
//            node.setInputKey(LogicOperateUtil.getInputKey(node.getExpress()));
            //if结点本身不需要inputKey,同位表达式结点下边会分析inputKey
            node.setExpressObject(genTNodeOperator(node.getParentNode(), node.getRealExpress()));
        }
    }

    /**
     * 生成操作符结点
     * @param parentNode
     * @param express
     * @return
     */
    protected TNode genTNodeOperator(TNode parentNode, String express){
        TNode node = new TNode();
        String nType = TemplateNodeTypeConfig.NODE_TYPE_OPERATOR;
        node.settLogicType(TemplateNodeTypeConfig.getInstance().getRegisterLogicTypeByKey
                (nType));
        node.setExpress(express);
        node.setParentNode(parentNode);

        ILogicHandleParse parse = getILogicHandleParse(node);
        parse.parseIOKeyForNode(node);
        return node;
    }
}
